% Gruppe 4
% Stefan Tuch
% Marcus Riesmeier
% Carsten Weißgerber
% Oliver Dölle


function [ tau_per, tau_on, time ] = func_pwmMeasurement( input_x, input_time )
%UNTITLED Misst Pulsdauer und Einschaltdauer
%   Detailed explanation goes here


%lokale Variablen
lastState = 0;
rising = [];
iRising = 1;
falling = [];
iFalling = 1;

for i = 1:length(input_x)
    if input_x(i) == 0 && lastState == 1             %fallende Zeiten sammeln
        lastState = 0;
        falling(iFalling) = input_time(i);
        iFalling = iFalling + 1;
    elseif input_x(i) ~= 0 && lastState == 0         %steigende Zeiten sammeln
        lastState = 1;
        rising(iRising) = input_time(i);
        iRising = iRising + 1;
    end
end

for i = 1:length(rising)-1
    time(i) = rising(i+1);
    tau_per(i) = rising(i+1) - rising(i);
    tau_on(i)  = falling(i) - rising(i); 
end


end

